<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>锁定的IP或用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script src="/js/xkube.js?v=1" charset="utf-8"></script>
</head>
<body>
<blockquote class="layui-elem-quote layui-text">
    注:登录失败太多的用户或IP被锁定后会在这里显示。
</blockquote>
<div class="layuimini-container">
    <div class="layuimini-main">
        <table class="layui-table" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="unLock">解锁</a>
            <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="longTermLock">永久封禁</a>
        </script>

    </div>
</div>
</body>
<script type="text/html" id="lockTimeTpl">
  {{# if (d.lockTime == '0') { }}
     <span style="color:#FF5722">不过期</span>
	{{# } else { }}
    <span>{{ d.lockTime}}</span>
{{# } }}
</script>	
<script>
    layui.use(['form', 'table','miniTab'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
            miniTab = layui.miniTab,
            miniTab.listen();

            form.render();

        table.render({
            elem: '#currentTableId',
            url: '/rbac/user/lockAct?act=list',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
      		      {field:'lockKey',sort: true, title: '对象'},
                {field:'lockTime',sort: true,templet: '#lockTimeTpl', title: '过期时间'},
                {title: '操作', minWidth: 250, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [25, 50, 100],
            limit: 25,
            page: false
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'unLock') {
                layer.confirm('确定解锁?', {icon: 3, title:'解锁提示',yes: function(index){
            			  $.ajax({
              			    url: "/rbac/user/lockAct?act=unLock&key="+data.lockKey,
              			    type: "get",
              			    //data: data,
              			    dataType: "json",
              			    success: function (resp) {
              						console.log(resp);
              						 if(resp.status){
              							 layer.msg('解锁成功', {icon: 1});
              							 //window.location.reload();
              							 obj.del();
              						 }else{
              							 layer.msg('解锁失败',{icon:2});
              						 }
              				  }
            		    });		  	  
                  },
              		cancel: function(index, layero){ 
              			layer.close(index);
              			console.log("不操作");
              		} 
        		    });                               
            }else if (obj.event === 'longTermLock') {
                layer.confirm('永久封锁?', {icon: 3, title:'封锁提示',yes: function(index){
            			  $.ajax({
              			    url: "/rbac/user/lockAct?act=longTermLock&key="+data.lockKey,
              			    type: "get",
              			    //data: data,
              			    dataType: "json",
              			    success: function (resp) {
              						console.log(resp);
              						 if(resp.status){
              							 layer.msg('封锁成功', {icon: 1});
              							 window.location.reload();
              							 //obj.del();
              						 }else{
              							 layer.msg('封锁失败',{icon:2});
              						 }
              				  }
            		    });		  	  
                  },
              		cancel: function(index, layero){ 
              			layer.close(index);
              			console.log("不操作");
              		} 
        		    });  
            }
        });

    });
</script>
</html>